﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SubSonic;
using SubSonic.Sugar;
using log4net;
using System.Reflection;  

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Heosoft.Register
{
    public partial class CompanyRegister : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
            }
        }
          
        private void TextReset()
        {
            this.txtCompanyEmail.Text = string.Empty;
            this.txtCompanyName.Text = string.Empty;
            this.txtCompanyAdd.Text = string.Empty;
            this.txtCompanyTel.Text = string.Empty;
            this.txtCompanyRemark.Text = string.Empty;
            this.drpCompanyType.SelectedIndex = 0;
        } 
          
        protected void tbnSubmit_Click(object sender, EventArgs e)
        {
            if (IsHaveEmail(this.txtCompanyEmail.Text.Trim()))
            {
                ExtAspNet.Alert.Show("该邮箱已注册！");
                return;
            } 
            try
            { 
                StoredProcedure sdp = new StoredProcedure("ProcCreateCopany");
                sdp.Command.AddParameter("@companyName", this.txtCompanyName.Text.Trim(), System.Data.DbType.String);
                sdp.Command.AddParameter("@companyEmail", this.txtCompanyEmail.Text.Trim(), System.Data.DbType.String);
                sdp.Command.AddParameter("@companyType", this.drpCompanyType.SelectedText.Trim(), System.Data.DbType.String);
                sdp.Command.AddParameter("@companyTel", this.txtCompanyTel.Text.Trim(), System.Data.DbType.String);
                sdp.Command.AddParameter("@companyAddress", this.txtCompanyAdd.Text.Trim(), System.Data.DbType.String);
                sdp.Command.AddParameter("@companyRemark", this.txtCompanyRemark.Text.Trim(), System.Data.DbType.String);
                sdp.Execute();
                Response.Redirect("~/Register/RegisterInfo.aspx?Email="
                                             + this.txtCompanyEmail.Text.Trim()); 
            }
            catch (Exception ex)
            {
                //创建日志记录组件实例
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                //记录错误日志
                log.Error("error", ex);
            }
        }

      

        protected void btnReset_Click1(object sender, EventArgs e)
        {
            TextReset();
        }

        private bool IsHaveEmail(string Email)
        {
            Where w = new Where();
            w.ColumnName = HsCompany.CompanyEmailColumn.ColumnName;
            w.ParameterValue = Email; 

            int i = 0;
            i = new Query(HsCompany.Schema)
                   .GetCount(HsCompany.CompanyEmailColumn.ColumnName, w);

            if (i == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
         
    }
}